#include "ALELoG.h"

CALELoG::CALELoG()
{
	//m_strFileName = "3.jpg"
}

CALELoG::CALELoG(CALStepItem* pStepItem)
{
	m_pStepItem = pStepItem;
}

CALELoG::~CALELoG()
{
}


void CALELoG::test()
{
	//test1();

	//test2();

	//test3();
}


void CALELoG::convert()
{
	if (m_pStepItem == NULL) return;

	try
	{
		CALSIELoG* pStepItem = (CALSIELoG*)m_pStepItem;

		int nFs = pStepItem->GetItemFs();

		if (nFs == 0)
		{
			Mat src_gray;
			int kernel_size = 3;
			Mat src = m_srcMat;

			GaussianBlur(src, src, Size(3, 3), 0, 0, BORDER_DEFAULT);
			cvtColor(src, src_gray, CV_RGB2GRAY);

			Mat dst, abs_dst;
			Laplacian(src_gray, dst, CV_16S, kernel_size);
			convertScaleAbs(dst, m_dstMat);

			//imshow("Laplace Demo", abs_dst);
		}
		else if (nFs == 1)
		{
			Mat gray, Kernel;
			Mat src = m_srcMat;
			//src = imread(m_strFileName);
			GaussianBlur(src, src, Size(3, 3), 0, 0, BORDER_DEFAULT);
			cvtColor(src, gray, CV_RGB2GRAY);
			//namedWindow("dstImage", 1);

			Kernel = (Mat_<double>(3, 3) << 1, 1, 1, 1, -8, 1, 1, 1, 1);
			Mat grad, abs_grad;
			filter2D(gray, grad, CV_16S, Kernel, Point(-1, -1));
			convertScaleAbs(grad, m_dstMat);

			//imshow("dstImage", abs_grad);
		}
		else if (nFs == 2)
		{
			Mat src, gray;

			src = imread(m_strFileName);
			GaussianBlur(src, src, Size(3, 3), 0, 0, BORDER_DEFAULT);
			cvtColor(src, gray, CV_RGB2GRAY);
			//namedWindow("srcImage", 1);
			//namedWindow("dstImage", 1);

			Mat grad, abs_grad;
			Laplacian(gray, grad, CV_16S, 3);
			convertScaleAbs(grad, abs_grad);
			m_dstMat = gray + abs_grad;

			//imshow("srcImage", gray);
			//imshow("dstImage", sharpped);
		}

		SetDstType(AL_DST_Mat_One);
	}
	catch (...)
	{

	}
}

void CALELoG::convert(const Mat &src, Mat &dst)
{

}

void CALELoG::test1()
{
	Mat src, src_gray;
	int kernel_size = 3;

	src = imread(m_strFileName);
	GaussianBlur(src, src, Size(3, 3), 0, 0, BORDER_DEFAULT);
	cvtColor(src, src_gray, CV_RGB2GRAY);

	Mat dst, abs_dst;
	Laplacian(src_gray, dst, CV_16S, kernel_size);
	convertScaleAbs(dst, abs_dst);

	imshow("Laplace Demo", abs_dst);

}

void CALELoG::test2()
{
	Mat src, gray, Kernel;

	src = imread(m_strFileName);
	GaussianBlur(src, src, Size(3, 3), 0, 0, BORDER_DEFAULT);
	cvtColor(src, gray, CV_RGB2GRAY);
	namedWindow("dstImage", 1);

	Kernel = (Mat_<double>(3, 3) << 1, 1, 1, 1, -8, 1, 1, 1, 1);
	Mat grad, abs_grad;
	filter2D(gray, grad, CV_16S, Kernel, Point(-1, -1));
	convertScaleAbs(grad, abs_grad);

	imshow("dstImage", abs_grad);

}

void CALELoG::test3()
{
	Mat src, gray;

	src = imread(m_strFileName);
	GaussianBlur(src, src, Size(3, 3), 0, 0, BORDER_DEFAULT);
	cvtColor(src, gray, CV_RGB2GRAY);
	namedWindow("srcImage", 1);
	namedWindow("dstImage", 1);

	Mat grad, abs_grad;
	Laplacian(gray, grad, CV_16S, 3);
	convertScaleAbs(grad, abs_grad);
	Mat sharpped = gray + abs_grad;

	imshow("srcImage", gray);
	imshow("dstImage", sharpped);
}